package com.sanbuTech.foundation.aop;

import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;


/**
 * 
 * 类描述：这是个消息通知的aop, 符合execution表达式的方法执行完成后会执行对应的方法去调用通知接口
 * 创建人：hyc   
 * 创建时间：2015年12月12日 下午3:16:21
 */
@Aspect  
@Component
public class MessagePushAOP {

	private static Logger logger = LoggerFactory.getLogger(MessagePushAOP.class);	//slf4j
	
//	@Autowired
//	private ThriftClient thriftClient;
	
	/*
	@Pointcut("execution(* com.threeStepServer.service.impl.AssignmentServiceImpl.*Duty*(..))")  
    private void pointcut(){}//定义一个切入点  
	 */	
	
	/**
	 * 审批节点状态state更新为CURRENT_APPROVER状态, 需要通知
	 * 应用场景: 正常走流程时, 轮到xxxx审批
	 * @param joinPoint
	
	@AfterReturning("execution(* com.threeStepServer.manager.AppApproveNodeManager.update(..))")
	public void afterApproveNodeUpdate(JoinPoint joinPoint){
		Object[] args = joinPoint.getArgs();
		long operId = (long)args[1];
		
		AppApproveNode node = (AppApproveNode)args[0];
		if(node.getFstate() == ApproveNodeStatus.CURRENT_APPROVER.getIndex()){
			//当更新状态为CURRENT_APPROVER, 需要消息提示一下
			
			WorkEventNotification weNotif = new WorkEventNotification();
			weNotif.setEvent_id(node.getFapplicationId());
			weNotif.setNotify_type(NotifyType.KANBAN.getIndex());
			weNotif.setSub_notify_type(SubNotifyType.APPROVE.getIndex());
			weNotif.setFrom_uid(operId);
			weNotif.setTo_uid(node.getFapproveUid());
			weNotif.setOrg_id(node.getForgId());
			weNotif.setPayload("有申请需要您审批");
			weNotif.setStatus(0);
			weNotif.setTimestamp(new Date().getTime()/1000);
			weNotif.setUpdatetime(0);
			
			thriftClient.sentEventNotification(weNotif);
		}
	}
	 */
	
	/**
	 * 申请状态
	 * @param joinPoint

	@AfterReturning("execution(* com.threeStepServer.manager.ApplicationManager.update(com.threeStepTech.model.ApplicationCommon, *))")
	public void afterApplicationUpdate(JoinPoint joinPoint){
		Object[] args = joinPoint.getArgs();
		long operId = (long)args[2];
		
		ApplicationCommon common = (ApplicationCommon)args[0];
		if(common.getFstate() == ApplicationStatus.RETRACE.getIndex()){
			
			WorkEventNotification weNotif = new WorkEventNotification();
			weNotif.setEvent_id(common.getFapplicationId());
			weNotif.setNotify_type(NotifyType.KANBAN.getIndex());
			weNotif.setSub_notify_type(SubNotifyType.APPROVE.getIndex());
			weNotif.setFrom_uid(operId);
			weNotif.setTo_uid(common.getFuid());
			weNotif.setOrg_id(common.getForgId());
			weNotif.setPayload("有申请需要您审批");
			weNotif.setStatus(0);
			weNotif.setTimestamp(new Date().getTime()/1000);
			weNotif.setUpdatetime(0);
			
			thriftClient.sentEventNotification(weNotif);
		}
	}
	 */
}
